package cn.ecut.dzy.pool;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @program: java-interview
 * @description: Callable有返回值
 * @author: DingZhenYun
 * @create: 2021-10-25 15:08
 **/

public class MyThread2 implements Callable {
    @Override
    public Object call() throws Exception {
        return 1024;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // FutureTask：实现了Runnable接口，构造函数又需要传入 Callable接口
        // 这里通过了FutureTask接触了Callable接口
        FutureTask<Integer> futureTask=new FutureTask<>(new MyThread2());

        Thread thread=new Thread(futureTask,"AAA");
        thread.start();
        // 判断futureTask是否计算完成
        while(!futureTask.isDone()) {

        }
        System.out.println(futureTask.get());
    }
}
